﻿using System.ComponentModel.Design;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using 开发自己的配置提供者.自己练习;

namespace 开发自己的配置提供者;

class Program
{
    static void Main(string[] args)
    {
        // ConfigurationBuilder cb = new ConfigurationBuilder();
        // cb.Add(new MyConfigSource(){Path = "web.config"});
        // var configRoot = cb.Build();
        // ServiceCollection service = new ServiceCollection();
        // service.AddScoped<WebConfigController>();
        // service.AddOptions().Configure<myWebConfig>(myWebConfig => configRoot.Bind(myWebConfig));
        //
        // using (var sp = service.BuildServiceProvider())
        // {
        //     var webConfigController = sp.GetRequiredService<WebConfigController>();
        //     webConfigController.PrintValue();
        // }

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.Add(new XmlConfigurationSouce() { Path = "web.config" });
        var configroot = cb.Build();
        ServiceCollection service = new ServiceCollection();
        service.AddScoped<MapWebConfigController>();
        service.AddOptions().Configure<MapWebConfig>(config => configroot.Bind(config));
        using (var sp = service.BuildServiceProvider())
        {
            var controller = sp.GetRequiredService<MapWebConfigController>();
            controller.Print();
        }
    }
}